<?php

namespace App\Models;

/**
 * Class UserReport
 * @property integer user_id 举报人
 * @property integer type_id 被举报的类型id
 * @property string type 被举报的类型(model name)
 * @property string content 举报内容
 * @property integer status 状态(1:举报成功、2:驳回)
 * @property User user
 */
class UserReport extends ApplicationModel
{
    protected $fillable = [
        'user_id',
        'type_id',
        'type',
        'content',
        'status',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function comment()
    {
        return $this->belongsTo(Comment::class, 'type_id')->withTrashed();
    }

    public function product()
    {
        return $this->belongsTo(Product::class, 'type_id')->withTrashed();
    }


    public function dynamic()
    {
        return $this->belongsTo(Dynamic::class, 'type_id')->withTrashed();
    }

    public function video()
    {
        return $this->belongsTo(Video::class, 'type_id')->withTrashed();
    }

    public function toUser()
    {
        return $this->belongsTo(User::class, 'type_id');
    }

    public function send_msg($content, $url = null)
    {
        //发送推送
        $message = new Message();
        $message->user_id = $this->user_id;
        $message->content = $content;
        $message->icon = Message::ICON;
        $message->url_schema = $url;
        $message->type_id = $this->id;
        $message->save();

    }
}
